package com.music.service.impl;

import com.music.common.BaseResult;
import com.music.dao.*;
import com.music.entity.CmForm;
import com.music.entity.CmMusic;
import com.music.entity.CmSinger;
import com.music.entity.req.FindAllCmFormMusicSinger;
import com.music.entity.req.FindAllSingerMusic;
import com.music.service.SmusicService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SmusicServiceImpl  implements SmusicService {
    @Resource
    SmusicMapper smusicMapper;
    @Resource
    SmusicSingerMapper smusicSingerMapper;
    @Resource
    FindAllSingerFormMapper findAllSingerForm;
    @Resource
    FindAllForm findAllForm;
    @Resource
    FindOneSinger findOneSinger;
    @Resource
    FindAllCmFormMusic findAllCmFormMusic;
    @Resource
    FindAllMusic findAllMusic;
    @Override
    public BaseResult findAll() {
        List<CmMusic> all = smusicMapper.findAll();
        BaseResult baseResult = new BaseResult();
        if(all!=null){
            baseResult.setCode(200);
            baseResult.setMessage("查询成功");
            baseResult.setData(all);
            return baseResult;
        }
        baseResult.setCode(201);
        baseResult.setMessage("查询失败");
        return baseResult;
    }

    @Override
    public BaseResult findAllSinger() {
        List<CmSinger> allSinger = smusicSingerMapper.findAllSinger();
        BaseResult baseResult = new BaseResult();
        if(allSinger!=null){
            baseResult.setCode(200);
            baseResult.setMessage("查询成功");
            baseResult.setData(allSinger);
            return baseResult;
        }
        baseResult.setCode(201);
        baseResult.setMessage("查询失败");
        return baseResult;
    }

    @Override
    public BaseResult findAllSingerForm(Integer id) {
        List<FindAllSingerFormMapper> allSingerForm = findAllSingerForm.findAllSingerForm(id);
        BaseResult baseResult = new BaseResult();
        if(allSingerForm!=null){
            baseResult.setCode(200);
            baseResult.setMessage("查询成功");
            baseResult.setData(allSingerForm);
            return baseResult;
        }
        baseResult.setCode(201);
        baseResult.setMessage("查询失败");
        return baseResult;
    }

    @Override
    public BaseResult findAllForm() {
        List<CmForm> all = findAllForm.findAll();
        BaseResult baseResult = new BaseResult();
        if(all!=null){
            baseResult.setCode(200);
            baseResult.setMessage("查询成功");
            baseResult.setData(all);
            return baseResult;
        }
        baseResult.setCode(201);
        baseResult.setMessage("查询失败");
        return baseResult;
    }

    @Override
    public BaseResult findOneSinger(Integer id) {
        List<FindAllSingerMusic> oneSinger = findOneSinger.findOneSinger(id);
        System.out.println(oneSinger);
        BaseResult baseResult = new BaseResult();
        if(oneSinger!=null){
            baseResult.setCode(200);
            baseResult.setMessage("查询成功");
            baseResult.setData(oneSinger);

            return baseResult;
        }
        baseResult.setCode(201);
        baseResult.setMessage("查询失败");
        return baseResult;
    }

    @Override
    public BaseResult findAllCmFormMusic(Integer id) {
        List<FindAllCmFormMusic> allCmFormMusic = findAllCmFormMusic.findAllCmFormMusic(id);
        BaseResult baseResult = new BaseResult();
        if (allCmFormMusic != null) {
            baseResult.setCode(200);
            baseResult.setMessage("查询成功");
            baseResult.setData(allCmFormMusic);

            return baseResult;
        }
        baseResult.setCode(201);
        baseResult.setMessage("查询失败");
        return baseResult;
    }

    @Override
    public BaseResult findAllFormMusicSinger() {
        List<FindAllCmFormMusicSinger> findAllCmFormMusicSingers = findAllMusic.selectAllMusic();
        BaseResult baseResult = new BaseResult();
        if (findAllCmFormMusicSingers != null) {
            baseResult.setCode(200);
            baseResult.setMessage("查询成功");
            baseResult.setData(findAllCmFormMusicSingers);

            return baseResult;
        }
        baseResult.setCode(201);
        baseResult.setMessage("查询失败");
        return baseResult;
    }
}
